package org.ligson.spark.shuangseqiu;

import org.ligson.spark.util.HttpUtil;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class CatNewestData {
    private static String lim = "\t";

    public static void main(String[] args) throws Exception {
        String text = HttpUtil.doGetText("http://www.17500.cn/getData/ssq.TXT");
        StringReader reader = new StringReader(text);
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line;
        List<StringBuilder> builders = new ArrayList<StringBuilder>();
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
            StringBuilder builder = new StringBuilder();
            String[] arrays = line.split(" ");
            String id = arrays[0];
            String date = arrays[1];
            String num1 = arrays[9];
            String num2 = arrays[10];
            String num3 = arrays[11];
            String num4 = arrays[12];
            String num5 = arrays[13];
            String num6 = arrays[14];
            String num7 = arrays[8];
            builder.append(id).append(lim).
                    append(date).append(lim).
                    append(num1).append(lim).
                    append(num2).append(lim).
                    append(num3).append(lim).
                    append(num4).append(lim).
                    append(num5).append(lim).
                    append(num6).append(lim).
                    append(num7);
            builders.add(builder);
        }
        bufferedReader.close();
        BufferedWriter writer = new BufferedWriter(new FileWriter("./src/main/resources/newestssq.txt"));
        for (int i = 0; i < builders.size(); i++) {
            writer.write(builders.get(i).toString());
            if (i != (builders.size() - 1)) {
                writer.newLine();
            }

        }
        writer.close();

    }
}
